<template>
  <div>
    <van-cell-group>
      <van-field
        v-model="user.phone"
        label="手机号"
        placeholder="请输入手机号"
      />
    </van-cell-group>
    <van-cell-group>
      <van-field
        v-model="user.password"
        label="密码"
        placeholder="请输入密码"
      />
    </van-cell-group>
    <van-cell-group>
      <van-field
        v-model="user.nickname"
        label="昵称"
        placeholder="请输入昵称"
      />
    </van-cell-group>
    <div class="btn"><van-button type="primary" @click="register">注册</van-button></div>
    
  </div>
</template>

<script>
import { reqRegister } from "../../http/http";
import { Toast } from 'vant';
export default {
  // 1.初始化表单数据
  data() {
    return {
      user: {
        phone: "",
        nickname: "",
        password: "",
      },
    };
  },
  methods: {
    // 3.注册逻辑
    register() {
      //发请求
      reqRegister(this.user).then((res) => {
        if (res.data.code === 200) {
          Toast.success(res.data.msg);
          this.$router.push("/login");
        }
      });
    },
  },
};
</script>

<style scoped>
  .btn{
    text-align: center;
    margin-top: 0.1rem;
  }
</style>